package com.wyx.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import javax.imageio.stream.FileImageOutputStream;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.sun.org.apache.xml.internal.resolver.helpers.PublicId;
import com.sun.xml.internal.ws.developer.StreamingAttachment;

public class UploadAction extends BaseAction{
	private String title;
	private File upload;
	private String uploadContentType;
	private String uploadFileName;
	private String savePath;
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public String getUploadContentType() {
		return uploadContentType;
	}
	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
/*	public String getSavePath(){
		return ServletActionContext.getServletContext().getRealPath(savePath);
	}
	private void doUpload(File file,String uploadFilePath) throws Exception{
		FileOutputStream fos=new FileOutputStream(uploadFilePath);
		FileInputStream fis=new FileInputStream(file);
		byte[] buffer=new byte[1024];
		int len=0;
		while((len=fis.read(buffer))!=-1){
			fos.write(buffer,0,len);
		}
		fis.close();
		fos.close();
		
		
	}*/
	
    public String execute() throws Exception{
    	/*String uploadPath=getSavePath()+"\\"+getUploadFileName();
    	doUpload(upload, uploadPath);*/
    	String path = ServletActionContext.getServletContext().getRealPath("/upload");
		// 创建目标文件对象
		File destFile = new File(path,uploadFileName);
		// 把上传的文件，拷贝到目标文件中
		FileUtils.copyFile(upload, destFile);
    	return SUCCESS;
    }
	

}
